Skip to content

Reject non-function bindings for single-case and partial active pattern names#19763

Draft
Copilot wants to merge 4 commits into
mainfrom
copilot/fix-active-pattern-definition
Draft

Reject non-function bindings for single-case and partial active pattern names#19763
Copilot wants to merge 4 commits into
mainfrom
copilot/fix-active-pattern-definition

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 18, 2026

The compiler previously rejected non-function multi-case active patterns ((|A|B|)) but still allowed equivalent invalid forms for single-case ((|A|)) and partial ((|A|_|)) names. This left declarations that tooling recognized as active patterns but could not be used in pattern positions.

  • Checker behavior aligned across active pattern forms

    • Updated post-inference active-pattern validation to run the function-typed check for all active pattern bindings, not only multi-case ones.
    • This makes FS1209 (Active pattern '...' is not a function) consistently apply to single-case and partial declarations as well.
  • Conformance coverage expanded

    • Extended E_ActivePatternNotAFunction.fs with explicit single-case and partial non-function declarations.
    • Updated expected diagnostics in Named.fs to assert all three FS1209 errors.
  • Example of newly-rejected declarations

    let (|C|) = 3
    let (|D|_|) = None
    // now reported as FS1209: Active pattern '...' is not a function

Copilot AI changed the title [WIP] Fix compiler allowing non-functions as active pattern names Reject non-function bindings for single-case and partial active pattern names May 18, 2026
Copilot finished work on behalf of T-Gro May 18, 2026 12:23
Copilot AI requested a review from T-Gro May 18, 2026 12:23
The PR's new validation rejects non-function active pattern bindings for
single-case and partial patterns (extending the existing multi-case check).
The RelaxWhitespace2.fs test file had several active patterns defined as
non-function values (|C|, |F|_|, |G|_|, etc.) since it tests whitespace
relaxation, not active pattern semantics.

Add parameters to make these active patterns function-typed while preserving
the multiline whitespace structure being tested.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 19, 2026

❗ Release notes required


✅ Found changes and release notes in following paths:

Change path Release notes path Description
src/Compiler docs/release-notes/.FSharp.Compiler.Service/11.0.100.md

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Member

@T-Gro T-Gro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix is correct and well-scoped. Removing the when _apinfo.ActiveTags.Length > 1 guard causes doesActivePatternHaveFreeTypars to be called for all active pattern bindings, which triggers the existing FS1209 side-effect check (activePatternIdentIsNotFunctionTyped) for single-case and partial patterns too, while FS1210 (free typars) remains restricted to multi-case via the if condition.

Correctness — verified that stripFunTy on a non-function type returns ([], ty) with no spurious free-typar error, so the error cascade is clean.

Tests — the RelaxWhitespace2.fs fixups make sense: those active patterns were never valid for pattern matching, and making them function-typed aligns with the test's real purpose (whitespace parsing, not active-pattern semantics).

Minor note (pre-existing, not blocking): doesActivePatternHaveFreeTypars reports FS1209 as a side effect despite its name suggesting a pure predicate. The same function is called from PatternMatchCompilation.fs at use-sites (lines 651, 720, 1415, 1623), meaning a non-function active pattern can get a duplicate FS1209 at each use. This was already the case for multi-case patterns before this PR, so it's not a regression — just something to be aware of for a future cleanup pass that separates the validation concern from the predicate.

@T-Gro T-Gro self-requested a review May 25, 2026 11:41
@T-Gro T-Gro added the AI-reviewed PR reviewed by AI review council label May 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI-reviewed PR reviewed by AI review council

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

Compiler allows non-functions to be bound to active pattern names

2 participants